<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts';
  require('echarts/theme/macarons');
  import resize from '@/views/dashboard/mixins/resize';

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      },
      projectId: {
        type: Number,
        required: true
      }
    },
    data() {
      return {
        chart: null,
        data: [],
        legend: [],
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart();
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.setOptions();
      },
      setOptions() {
        this.chart = echarts.init(this.$el, 'macarons');
        let option = {
          // title: {
          //   text: '百章每期累计金额完成统计',
          //   subtext: '单位（万元）',
          //   left: 'center'
          // },
          // tooltip: {
          //   trigger: 'item'
          // },
          // legend: {
          //   top: 50,
          //   data: response.axis
          // },
          // grid: {
          //   top: 90,
          //   show: false
          // },
          xAxis: {
            // 去除x轴的背景网格
            splitLine: {
              show: false,
            },
            type: 'category',
            boundaryGap: false,
            data: ['第一期', '第二期', '第三期', '第四期', '第五期', '第六期', '第七期']
          },
          yAxis: {
            axisLine: {show: true},
            axisTick: {show: true},
            splitArea: {show: false},
            splitLine: {show: false},
            type: 'value',
            // axisLabel: {
            //   formatter: '{value}'
            // }
          },
          series: {
            // name: 'Highest',
            type: 'line',
            data: [258, 845, 768, 1254, 846, 1864, 1543],
            // areaStyle: {}
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                { type: 'min', name: 'Min' }
              ]
            },
            markLine: {
              data: [{ type: 'average', name: 'Avg' }]
            },
            smooth: false
          }
        };
        this.chart.setOption(option);
      }
    }
  }

</script>
